package com.Questions.doublePointer;


/**
 * 爱生气的书店老板
 */
public class leetcode1052 {
    // 方法一 滑动窗口
    public int maxSatisfied1(int[] customers, int[] grumpy, int minutes) {
        int n = customers.length;
        int max = 0;
        for(int i = 0; i < n; ++i) {// 遍历不生气连续时间的开始时间
            int sum = 0;
            for(int j = 0; j < n; ++j) {
                if( (j >= i && j < i + minutes) || (grumpy[j] == 0) ) {// 不生气的时间
                    sum += customers[j];
                }
            }
            max = Math.max(max,sum);
        }
        return max;
    }
    public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
        int total = 0;
        int n = customers.length;
        for (int i = 0; i < n; i++) {
            if (grumpy[i] == 0) {
                total += customers[i];
            }
        }
        int increase = 0;
        for (int i = 0; i < minutes; i++) {
            increase += customers[i] * grumpy[i];
        }
        int maxIncrease = increase;
        for (int i = minutes; i < n; i++) {
            increase = increase - customers[i - minutes] * grumpy[i - minutes] + customers[i] * grumpy[i];
            maxIncrease = Math.max(maxIncrease, increase);
        }
        return total + maxIncrease;
    }
}
